import config from "./config"
//封装函数发送请求
export default function request(url , data , method="GET"){
  return new Promise((resolve , reject) => {
    wx.request({
      url: 'http://127.0.0.1:3000' + url,
      // url: config.moblieHost + url,
      data,
      //请求携带cookies   
      header:{
        cookie: wx.getStorageSync('cookies') && wx.getStorageSync('cookies').join(";")
      },
      method,
      success: (res) => {
        //判断是登录请求就设置cookies到存储中
        if(data.isLogin){
            wx.setStorageSync('cookies', res.cookies)
        }
        resolve(res.data)
      },
      fail: (error) => {
        reject(error)
      }
    })
  })
}